package com.itcast.donkey.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.activity.TravelInItemActiity;
import com.itcast.donkey.modles.TravelInHeadImageModels;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/14.
 */
public class InHeadTravelAdapter extends RecyclerView.Adapter<InHeadTravelAdapter.Myholder> {
    private Context context;
    private List<TravelInHeadImageModels.TripsBean> modle = new ArrayList<>();

    public InHeadTravelAdapter(Context context, List<TravelInHeadImageModels.TripsBean> modle) {
        this.context = context;
        this.modle = modle;
    }

    @Override
    public Myholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_in_head_travel, null);
        Myholder myholder = new Myholder(view);
        return myholder;
    }

    @Override
    public void onBindViewHolder(Myholder holder, final int position) {
        holder.name.setText(modle.get(position).getName());
        holder.date.setText(modle.get(position).getStart_date() + ""+" / ");

        holder.days.setText(modle.get(position).getDays() + "天,");
        holder.photosCount.setText(modle.get(position).getPhotos_count() + "图");
        Picasso.with(context).load(modle.get(position).getFront_cover_photo_url()).into(holder.frontCoverPhoto);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转事件
                int id = modle.get(position).getId();
                String hID = Integer.toString(id);
                Intent intent = new Intent(context, TravelInItemActiity.class);
                intent.putExtra("hID", hID);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return modle.size();
    }

    public class Myholder extends RecyclerView.ViewHolder {
        private ImageView frontCoverPhoto;
        private TextView name;
        private TextView date;
        private TextView days;
        private TextView photosCount;

        public Myholder(View itemView) {
            super(itemView);
            frontCoverPhoto = (ImageView) itemView.findViewById(R.id.front_cover_photo);
            name = (TextView) itemView.findViewById(R.id.name);
            date = (TextView) itemView.findViewById(R.id.date);
            days = (TextView) itemView.findViewById(R.id.days);
            photosCount = (TextView) itemView.findViewById(R.id.photos_count);
        }
    }
}
